<?php
/*----------------------------------------------------------------------
#Youjoomla NS 1 News Slider for Joomla 1.5 Version 1.0
# ----------------------------------------------------------------------
# Copyright (C) 2007 You Joomla. All Rights Reserved.
# Designed by: Youjoomla.com
# Commercial
# Website: http://www.youjoomla.com// Copyright (c) 2006 - 2008 Youjoomla LLC
# This code cannot be redistributed without permission from Youjoomla - http://www.youjoomla.com.
# More info at http://www.youjoomla.com 
# Developer: Dragan Todorovic
------------------------------------------------------------------------*/

// no direct access
defined('_JEXEC') or die('Restricted access');
require_once (JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php');
$database					=& JFactory::getDBO();
$mosConfig_absolute_path	= JPATH_ROOT;
$mosConfig_live_site 		= JURI :: base();  
  
require_once('modules/mod_yj_ns1/lib/slike.php');
echo "<!-- http://www.Youjoomla.com News Slider 1  for Joomla 1.0 starts here --> ";
//$phpversion=$params->get('phpversion',"1");
$mootools=$params->get('mootools',"0");
$compress=$params->get('compress',"0");

$get_items = $params->get('get_items',1);
$nitems = $params->get ('nitems',4);
$chars = $params->get ('chars',200);
$width = $params->get ('width','420px');
$height =  $params->get ('height','200px');


$time =  $params->get ('time','5000');
$duration =  $params->get ('duration','400');
$orient = $params->get ('orient','1'); // 1  or 0
$intitle = $params->get ('intitle','#C50403');

$type =  $params->get ('type','scroll'); 
$introheight = $params->get ('introheight','40px');
$introopacity = $params->get ('introopacity','0.8');
$transbgcol = $params->get ('transbgcol','#000');
$introfont = $params->get ('introfont','#fff');
$shownav = $params->get ('shownav','1');
$border = $params->get ('border','10px solid #efefef');
$outborder = $params->get ('outborder','1px solid #ccc');
$logo = $params->get ('logo','modules/mod_yj_ns1/images/logo.png');
$showlogo = $params->get ('showlogo','1');
$logoheight = $params->get ('logoheight','20px');
$logowidth = $params->get ('logowidth','135px');
$logolink = $params->get ('logolink','http://www.youjoomla.com');
$linktarget = $params->get ('linktarget','_blank');
$uselogolink = $params->get ('uselogolink','0');
$logotitle = $params->get ('logotitle','Visit Youjoomla.com');
$use_tags = $params->get('use_tags',"<a><b><span>");
$style_ns1css = $params->get ('style_ns1css','1');// 1  i 2
$readmore = $params->get ('readmore','Read more...');
$onpageload = $params->get ('onpageload','1');
$pngfix = $params->get ('pngfix','1');

$transp = $params->get ('transp','75');

$intotransbgcol = $params->get ('intotransbgcol','transparent');
$loader = $params->get ('loader','1'); // 1 and 0

$slide_logo = $params->get ('slide_logo','1');
$slidlogo_delay = $params->get ('slidlogo_delay','1000');
$jQuery = $params->get ('jQuery','1');

$ordering = $params->get('ordering',1);// 1 = ordering | 2 = popular | 3 = random 

////////////////////////// /BRAKE YOUR BRAIN! I BROKE MINE :) //////////////////////////////////


if($ordering ==1){
$order = 'ordering';
}elseif($ordering == 2){
$order = 'hits';
}elseif ($ordering == 3){
$order = 'RAND()';
}

if($transp == 25 || $transp == 50 || $transp == 75 ){

$transbg = ''.$intotransbgcol.' url('.$mosConfig_live_site.'/modules/mod_yj_ns1/images/op'.$transp.'.png)';
}elseif($transp == 100){
$transbg = $intotransbgcol;
}







  if ($onpageload == 1) {
    $direction="forward";
  }else {
    $direction="pause";
  }



if ($style_ns1css == 1){
$aw = $width - 294;
$ah = $height -0 ;
}else{
$aw = $width - 0;
$ah = $height - $introheight;
}
$logomargin = $height -$logoheight -$border*2;
 
/////////////////////////////////////////////////////////////
$style2h = $height - $border*2; 



$posnav = $width -24 - $border; 


$nspoz = $border * 1;

$shw = $border *2;
$shh = $border *2;
$sholderw = $width - $shw;
$sholderh = $height - $shh;
$main_w = $sholderw * $nitems ;
$main_h =  $sholderh * $nitems ;
if ($shownav == 1){
$zin ='3000';
}else{
$zin ='-1';
}
$width_s = $width -20;

$getm = $sholderh - $introheight ;
$st2mtop = $getm - 0;
	
if($compress ==1 ){
$mooext= 'php';
$cssext ='php';
}else{
$mooext= 'js';
$cssext ='css';
}



if ($mootools == 1){
  $linktag_ns1.= '<script src="modules/mod_yj_ns1/js/mootools.'.$mooext.'" type="text/javascript"></script>';

  }else{}

$linktag_ns1.= '<script src="'.$mosConfig_live_site.'/modules/mod_yj_ns1/css/style.css" type="text/javascript"></script>';

$linktag_ns1.= '<script src="'.$mosConfig_live_site.'/modules/mod_yj_ns1/lib/ns1slide.'.$mooext.'" type="text/javascript"></script>';




$slyle_ns1="<style type=\"text/css\">";
if ($style_ns1css == 1){
$slyle_ns1.="
a.ns1readon,a.ns1readon:link,
a.ns1readon:active,
a.ns1readon:visited{
height:20px;
width:120px;
display:block;
background:url($mosConfig_live_site/modules/mod_yj_ns1/images/readonns1green.gif) no-repeat left top;
color:#fff;
text-align:left;
text-indent:15px;
line-height:20px;
margin-top:10px;
font-weight:bold;
}
a.ns1readon:hover {
height:20px;
width:120px;
display:block;
color:#fff;
background:url($mosConfig_live_site/modules/mod_yj_ns1/images/readonns1_h.gif) no-repeat left top;
text-align:left;
text-indent:15px;
line-height:20px;
margin-top:10px;
font-weight:bold;
}

#nslogo a{
display:block;
height:{$logoheight};
width:{$logowidth};
}

#naviga{
height:20px;
text-align:left;
display:none;
position:absolute;
top:50%;
background:transparent;
}

#desno{
position:absolute;
left:{$posnav}px;
z-index:310;
}
#lijevo{
position:absolute;
left:{$nspoz}px;
z-index:311;
}
#naviga a{
color:#fff;
}
.intros{
height: {$style2h}px !important;
width:200px;
color:{$introfont};
text-indent: 0;
overflow: hidden;
z-index:301;
float:left;
margin-left:50px;
padding:0px 10px 0px 10px;
text-align:left;
background:{$transbg};
}
.intros p,.intros h3{
padding:5px 0px;
}
a.nstitle,a.nstitle:link,
a.nstitle:active,
a.nstitle:visited{
font-weight:bold;
font-size:20px;
text-decoration: none;
color:#ffffff;
}


a.nstitle:hover{
font-weight:bold;
font-size:20px;
text-decoration: none;
color:{$intitle};
}


";

$slyle_ns1.="</style>";
}else {
$slyle_ns1.="
#nslogo a{
display:block;
height:{$logoheight};
width:{$logowidth};
}

#naviga{
height:20px;
text-align:left;
display:none;
position:absolute;
top:50%;
background:transparent;
}

#desno{
position:absolute;
left:{$posnav}px;
z-index:310;
}
#lijevo{
position:absolute;
left:{$nspoz}px;
z-index:311;
}
#naviga a{
color:#fff;
}
.intros{
height: {$introheight} !important;
list-style-type:none;
width:{$width_s}px;
color:{$introfont};
text-indent: 0;
overflow: hidden;
bottom: 0px !important;
float:left;
margin-top:{$st2mtop}px;
padding:0px;
text-align:left;
background:{$transbg};
}
.intros p,.intros h3{
padding:0 5px 0 5px;
}
a.nstitle,a.nstitle:link,
a.nstitle:active,
a.nstitle:visited{
font-weight:bold;
font-size:20px;
text-decoration: none;
color:#ffffff;
}


a.nstitle:hover{
font-weight:bold;
font-size:20px;
text-decoration: none;
color:{$intitle};
}


";

$slyle_ns1.="</style>";



}
$linktag_ns1.=$slyle_ns1;
if ($pngfix == 1){ 
$slyle_nsie1="<!--[if lte IE 6]>
<style type=\"text/css\">
#nslogo,#desno,#lijevo{
	behavior: url($mosConfig_live_site/modules/mod_yj_ns1/css/iepngfix.htc);
}

</style>";
$slyle_nsie1.="<![endif]-->";
$linktag_ns1.=$slyle_nsie1;
}

if ($style_ns1css == 1){
$slyle_nsie2="<!--[if lte IE 6]>
<style type=\"text/css\">
.intros{
background-color:#313030;
background-image:none;
filter:alpha(opacity=80);
margin-left:20px;
}
</style>";
$slyle_nsie2.="<![endif]-->";
}else{
$slyle_nsie2="<!--[if lte IE 6]>
<style type=\"text/css\">
.intros{
background-color:#313030;
background-image:none;
filter:alpha(opacity=80);
}
</style>";
$slyle_nsie2.="<![endif]-->";




}
$linktag_ns1.=$slyle_nsie2;

if ($jQuery == 1){
  $linktag_ns1.= '<script type="text/javascript">jQuery.noConflict();</script>';

  }

$mainframe->addCustomHeadTag($linktag_ns1);

  $now 		    = date('Y-m-d H:i:s');
  $database 	=& JFactory::getDBO();
  $nullDate 	= $database->getNullDate();

  


$get_items = $params->get('get_items',1);
$nitems = $params->get ('nitems',5);
$chars = $params->get ('chars',200);


		$db			=& JFactory::getDBO();
		$user		=& JFactory::getUser();
		$userId		= (int) $user->get('id');
		$aid		= $user->get('aid', 0);

		$contentConfig = &JComponentHelper::getParams( 'com_content' );
		$access		= !$contentConfig->get('shownoauth');

		$nullDate	= $db->getNullDate();

		$date =& JFactory::getDate();
		$now = $date->toMySQL();

		$where		= 'a.state = 1'
			. ' AND ( a.publish_up = '.$db->Quote($nullDate).' OR a.publish_up <= '.$db->Quote($now).' )'
			. ' AND ( a.publish_down = '.$db->Quote($nullDate).' OR a.publish_down >= '.$db->Quote($now).' )'
			;



$sql = 'SELECT a.*, ' .
' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug,'. 
' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END as catslug'.
			' FROM #__content AS a' .
			' INNER JOIN #__categories AS cc ON cc.id = a.catid' .
			' INNER JOIN #__sections AS s ON s.id = a.sectionid' .
			' WHERE '. $where .' AND cc.id = '.$get_items.'' .
			($access ? ' AND a.access <= ' .(int) $aid. ' AND cc.access <= ' .(int) $aid. ' AND s.access <= ' .(int) $aid : '').
			' AND s.published = 1' .
			' AND cc.published = 1' .
			' ORDER BY '.$order .' LIMIT 0,'.$nitems.'';





$database->setQuery( $sql );
$load_items = $database->loadObjectList();

?>


<?php if ($shownav == 1){ ?> 
<script type="text/javascript">
window.addEvent('domready', function() {

   $('slide_holder').addEvent('mouseenter', function() {
document.getElementById('naviga').style.display = 'block';

	});
	
	   $('slide_holder').addEvent('mouseleave', function() {
document.getElementById('naviga').style.display = 'none';
	});

});
</script>
		<?php } ?>



<div id="slide_holder" style="background:<?php echo $transbgcol ?>;position:relative;width:<?php echo $width?>; height:<?php echo $height?>; border:<?php echo $outborder ?>; overflow:hidden;margin:0 auto; text-align:center;">


<div id="naviga"><a id="lijevo" href="javascript: void(0)"><img src="<?php echo $mosConfig_live_site ?>/modules/mod_yj_ns1/images/left.png" alt="Prev" title="Prev" width="24px" height="24px" /></a><a id="desno" href="javascript: void(0)" ><img src="<?php echo $mosConfig_live_site ?>/modules/mod_yj_ns1/images/right.png" alt="Next" title="Next" width="24px" height="24px"  /></a></div>



<div id="pozicija" style="width:<?php echo $sholderw?>px;height:<?php echo $sholderh?>px;border:<?php echo $border ?>;margin:0 auto;  text-align:center;">








<?php if($showlogo == 1) { ?>


<?php if($slide_logo == 1) { ?>
<div id="nslogo" style="display:none;height:<?php echo $logoheight ?>;width:<?php echo $logowidth ?>;position:absolute;z-index:400;top:<?php echo $nspoz ?>px;right:<?php echo $nspoz ?>px;"><?php } ?>


<?php if($slide_logo == 2) { ?>
<div id="nslogo" style="height:<?php echo $logoheight ?>;width:<?php echo $logowidth ?>;position:absolute;z-index:400;bottom:<?php echo $nspoz ?>px;right:<?php echo $nspoz ?>px;"><?php } ?>



<?php if ($uselogolink == 1) { ?><a href="<?php echo $logolink ?>" target="<?php echo $linktarget ?>" title="<?php echo $logotitle ?>"><img src="<?php echo $logo ?>" title="<?php echo $logotitle ?>" width="<?php echo $logowidth ?>" height="<?php echo $logoheight ?>"  alt="<?php echo $logotitle ?>" /></a><? } ?></div><?php } ?>







			<div id="yj_ns1" class="yj_ns1" style="width:<?php echo $sholderw?>px;height:<?php echo $sholderh?>px;overflow:hidden;">
                  
               <?php  if ($orient == 1 ) { ?>
                  <div style="width:<?php echo $main_w?>px;">
                  <?php } ?>
                   <?php  if ($orient == 0 ) { ?>
                  <div style="height:<?php echo $main_h?>px;">
      <?php } ?>
      
      <?php foreach ( $load_items as $row ) {
require('modules/mod_yj_ns1/lib/slike1.php');

$link = ContentHelperRoute::getArticleRoute($row->slug, $row->catslug, $row->sectionid);
$intro 	= substr(strip_tags($row->introtext),0,$chars)."...";
if(isset($img_url)) $img_out=$img_url;


?>

<?php  if ($orient == 1 ) { ?>
   <div onclick="window.location.href='<?php echo JRoute::_($link) ?>';" style="width:<?php echo $sholderw ?>px;height:<?php echo $sholderh ?>px;float:left;background:url(<?php echo $img_out?>) no-repeat center center;padding:0px !important; cursor:pointer;">
   
   <?php } ?>
   
   <?php  if ($orient == 0 ) { ?>
   
   <div onclick="window.location.href='<?php echo JRoute::_($link) ?>';" style="width:<?php echo $sholderw ?>px;height:<?php echo $sholderh ?>px;float:left;background:url(<?php echo $img_out?>) no-repeat center center;padding:0px !important; cursor:pointer;">
<?php } ?>


<div class="intros">
<h3><a class="nstitle" href="<?php echo JRoute::_($link) ?>" title="<?php echo $row->title ?>"><?php echo $row->title ?></a></h3>

<p><?php echo $intro?>
<?php if ($style_ns1css == 1){ ?>
<br  /><a class="ns1readon"  href="<?php echo JRoute::_($link) ?>" title="<?php echo $row->title ?>"><?php echo $readmore ?></a><?php } ?>
</p>
</div>






</div>



  <?php } ?>





</div>
</div> 




</div>





</div>

<script type='text/javascript'>
var  ns1_slider = new YJns1Slide("yj_ns1",{type: "<?php echo $type ?>", direction: "<?php echo $direction ?>", auto: "loop", time: <?php echo $time ?>,wait:true, duration: <?php echo $duration ?>});
var ns1_slide_type='<?php echo $type ?>';

<?php  if ($onpageload == 1) { ?>
$('pozicija').addEvent('mouseenter', function(){ns1_slider.pauza();});
$('pozicija').addEvent('mouseleave', function(){ns1_slider.radi(ns1_slide_type);});
  <?php } ?>
  
  <?php  if ($onpageload == 0) { ?>
$('pozicija').addEvent('mouseenter', function(){ns1_slider.pauza();});
$('pozicija').addEvent('mouseleave', function(){ns1_slider.pauza();});
  <?php } ?>
  

<?php if ($shownav == 1){ ?> 
$('desno').addEvent('click', function(){ns1_slider.naprijed(ns1_slide_type);});
$('lijevo').addEvent('click',function(){ns1_slider.nazad(ns1_slide_type);}); <?php } ?>
</script>


<?php if($showlogo == 1) { ?>
<?php if($slide_logo == 1) { ?>
<script type="text/javascript">
window.addEvent('domready', function(){
var box = $('nslogo');
var fx = box.effects({duration: <?php echo $slidlogo_delay ?>, transition: Fx.Transitions.Bounce.easeOut});

fx.start({
}).chain(function() {
this.start.delay(0, this, {'margin-top' : -10,'opacity':0});
}).chain(function() {
box.style.display="block";
this.start.delay(0100, this, {'margin-top' : <?php echo $logomargin ?>,'opacity':1});
});
});

</script><?php } ?><?php } ?>